#!/bin/bash
#############################################################
# Name:        Supportconfig Plugin for iPrint
# Description: Gathers iPrint troubleshooting information
# License:     GPLv2
# Authors/Contributors:
#              Jeremy Meldrum (jmeldrum@novell.com)
#              Jason Record (jrecord@novell.com)
#	           Pritam Pal Singh (spritampal@novell.vom 	
#                (Initial supportconfig plugin port)
# Modified:    2013 October 29
#############################################################
SVER=3.0.0
RCFILE="/usr/lib/supportconfig/resources/scplugin.rc"
PGCONF="/etc/opt/novell/iprint-plugin/iprint-plugin.conf"
LOG_LINES=200	#0 means include the entire file
LOG_LINES2=100
LOG_LINES3=400

[ -s $RCFILE ] && . $RCFILE || { echo "ERROR: Initializing resource file: $RCFILE"; exit 1; }
[ -s $PGCONF ] && . $PGCONF || { echo "ERROR: Initializing configuration file: $PGCONF"; exit 2; }

section_header "Supportconfig Plugin for iPrint, v${SVER}"
plugin_message "Section #1: RPM Validation"
plugin_message "Section #2: Rights Listing"
plugin_message "Section #3: Static Directories"
plugin_message "Section #4: File Output"
plugin_message "Section #5: eDirectory and Certificate Information"
plugin_message "Section #6: Miscellaneous Commands"
plugin_message "Section #7: Log Output Files"
plugin_message


if [ -z "$EDIR_USERNAME" ]; then
	plugin_tag "WARNING" "Run iPrintInfo -h for additional information"
	plugin_message "Secure commands will not be performed"; echo
fi

declare -a rpmArray
declare -a fileArray
declare -a staticArray
#declare -a psmArray
declare -a grepArray
errorFlag="1"
tempVar=""
managerName=""
tmpSrvName=""
oesVersion=""
applianceVersion=""
#Labels
RIGHTS_LABEL="Directory Listings"
RPM_LABEL="RPM Check"
EDIR_LABEL="eDir and Certs"
COMM_LABEL="Command"
LOG_LABEL="Log File"
XML_LABEL="XML File"
FILE_LABEL="Configuration File"

#Stores the server DNS or IP address variables
iprint_ssl_URL=""
ipsmd_conf_dsserver1=""
ipsmd_conf_psmhostaddress=""
nam_conf_server=""


###################################################
PackageValidation ()
{
	plugin_tag "Section #1" "RPM Validation"
	echo "RPM Verify Key:"
	
	echo "Summary: Each of the 8 characters denotes the result of a comparison of attribute(s) of the file to the value of those attribute(s) recorded in the database."
	echo "The (mnemonically emBoldened) character denotes failure of the corresponding --verify test:"
	echo
	echo ". Test passed"
	echo "? Test not performed"
	echo "S file Size differs"
	echo "M Mode differs (includes permissions and file type)"
	echo "5 MD5 sum differs"
	echo "D Device major/minor number mismatch"
	echo "L readLink(2) path mismatch"
	echo "U User ownership differs"
	echo "G Group ownership differ"
	echo "T mTime differs"
	echo
	echo "c configuration file"
	echo "d documentation file"
	echo "g ghost file (file content is not included in the package payload)"
	echo "l license file"
	echo "r readme file"
	echo

	for i in $rpmArray; do
		validate_rpm $i
	done
}
###################################################
ListRights ()
{
	plugin_tag "Section #2" "Rights Listings"
	for i in $rpmArray; do
		plugin_tag "RPM Check" "$i"
		rpm -ql $i | xargs -d '\n' ls -ld; echo
	done
}
###################################################
#This function lists the rights of directories specific to iprint.
ListRightsStatic ()
{
	plugin_tag "Section #3" "Static Directories"
	pathsToList="/var/opt/novell/iprint/ /etc/opt/novell/iprint/conf/ /var/opt/novell/run/iprint/ /opt/novell/iprint/bin/ /etc/opt/novell/iprint/httpd/conf/"
	
	if [ ! -z $applianceVersion ];then
		pathsToList="$pathsToList /etc/opt/novell/iprintmobile/ /var/opt/novell/iprintmobile/ /var/opt/novell/iprintmobile/jobs/ /vastorage/iprint/ /etc/avahi/ /etc/avahi/services/"
	fi
	
	for pathVar in $pathsToList
	do
		plugin_tag "$RIGHTS_LABEL" "$pathVar"
		ls -al $pathVar; echo
		ls -aln $pathVar; echo
	done

	pathsToList="/var/opt/novell/iprint/mod_ipp/ /var/opt/novell/iprint/htdocs/"	
	for pathVar in $pathsToList
	do
		plugin_tag "$RIGHTS_LABEL" "$pathVar"	
		ls -Rl $pathVar; echo
	done

	pathsToList="/var/opt/novell/log/iprint/ /var/opt/novell/iprint/resdir/"
	if [ ! -z $applianceVersion ]; then
		pathsToList="$pathsToList /var/opt/novell/log/iprintmobile/"	
	fi
	
	for pathVar in $pathsToList
	do
		plugin_tag "$RIGHTS_LABEL" "$pathVar"
		ls -alh $pathVar; echo
	done
	managerName=`ls -al /etc/opt/novell/iprint/conf/ipsmd.conf | awk -F/ '{print $(NF-0)}' | sed 's/.ipsmd.conf//'` 
	#managerName=` ls -al /etc/opt/novell/iprint/conf/ipsmd.conf | cut -d/ -f13 | sed 's/.ipsmd.conf//'`
	plugin_tag "$RIGHTS_LABEL" "/var/opt/novell/iprint/$managerName.psm"
	ls -al /var/opt/novell/iprint/"$managerName.psm"; echo
	
	pathsToList="driver_linux-2.4_x86-32_en driver_mac-os-x_noarch_en driver_windows-95_x86-32_en driver_windows-nt-4_x86-32_en driver_windows-nt-5.1_x86-32_en driver_windows-nt-5_x86-32_en driver_windows-nt-6_x86-32_en driver_windows-nt-6_x86-64_en driver_windows-nt-6.1_x86-32_en driver_windows-nt-6.1_x86-64_en driver_windows-nt-6.2_x86-32_en driver_windows-nt-6.2_x86-64_en"
	for pathVar in $pathsToList
	do
		if [ -d /var/opt/novell/iprint/resdir/${pathVar} ]; then
			plugin_tag "$RIGHTS_LABEL" "/var/opt/novell/iprint/resdir/${pathVar}"
			ls -al /var/opt/novell/iprint/resdir/${pathVar}; echo
		fi
	done

	
	#NSS Rights listing
#	if [ -h "/var/opt/novell/iprint" ]; then
#		plugin_tag "$RIGHTS_LABEL" "rights show -f /var/opt/novell/log/iprint"
#		rights show -f /var/opt/novell/log/iprint; echo

#		plugin_tag "$RIGHTS_LABEL" "rights show -f /var/opt/novell/iprint"
#		rights show -f /var/opt/novell/iprint; echo
#	fi

}


###################################################
FileOutput ()
{
	plugin_tag "Section #4" "File Output"
	
	plugin_tag "Configuration File" "/etc/opt/novell/iprint/conf/idsd.conf"
	sed -e '/^IDSObjectPasswd/d' /etc/opt/novell/iprint/conf/idsd.conf; echo
	
	plugin_tag "Configuration File" "/etc/opt/novell/iprint/conf/ipsmd.conf"
	sed -e '/^PSMObjectPasswd/d' /etc/opt/novell/iprint/conf/ipsmd.conf; echo		

	pconf_files "/etc/opt/novell/iprint/httpd/conf/iprint_g.conf /etc/opt/novell/iprint/httpd/conf/iprint_ssl.conf /var/opt/novell/iprint/htdocs/iprint.ini"

	NCS_MGR_NAME=$(grep -i ipsmd /var/opt/novell/ncs/*.load | cut -d: -f1 | grep  iPrint_Template --invert-match)	
	if [ -n "$NCS_MGR_NAME" ]; then
		pconf_files $NCS_MGR_NAME
	else 
		plugin_tag "Configuration File" "iPrint NSS Load Script Does Not Exist"
		
	fi

        NCS_MGR_NAME=$(grep -i ipsmd /var/opt/novell/ncs/*.unload | cut -d: -f1 | grep  iPrint_Template --invert-match)
        if [ -n "$NCS_MGR_NAME" ]; then
                pconf_files $NCS_MGR_NAME
        else
		plugin_tag "Configuration File" "iPrint NSS Unload Script Does Not Exist"
        fi        
	if [ $oesVersion == "11" ]; then
		pconf_files "/etc/nam.conf /etc/novell-release /etc/SuSE-release /etc/hosts /etc/apache2/httpd.conf /etc/apache2/vhosts.d/vhost-ssl.conf /etc/sysconfig/apache2 /etc/sysconfig/proxy /etc/permissions.d/iprint /opt/novell/iprintmgmt/lib/Logger.properties"
	else 

		pconf_files "/etc/nam.conf /etc/novell-release /etc/SuSE-release /etc/hosts /etc/openwbem/openwbem.conf /etc/apache2/httpd.conf /etc/apache2/vhosts.d/vhost-ssl.conf /etc/sysconfig/apache2 /etc/sysconfig/proxy /etc/permissions.d/iprint"
	fi

	if [ ! -z $applianceVersion ]; then
		pconf_files "/etc/Novell-VA-release /etc/opt/novell/iprintmobile/conf/iprintmobile.conf /etc/cups/printers.conf /etc/opt/novell/iprintmobile/conf/mime.types /etc/opt/novell/iprintmobile/conf/iprint_mobile_apache.conf /etc/opt/novell/iprintmobile/conf/backupList /etc/opt/novell/iprintmobile/conf/additionalBackupList /etc/opt/novell/iprintmobile/conf/restore.properties /var/opt/novell/iprintmobile/audit.csv /etc/avahi/avahi-daemon.conf /etc/avahi/hosts /etc/default/jetty"
	fi

	plugin_tag "$FILE_LABEL" "cat /etc/passwd"
	cat /etc/passwd | sort -d
	echo; echo
	plugin_tag "$FILE_LABEL" "cat /etc/group"
	cat /etc/group | sort -d
	echo; echo
}
###################################################
checkOESVersion ()
{
	oesVersion=$(cat /etc/novell-release | grep VERSION | cut -d= -f2 |sed -e 's/^[ \t]*//')
}

checkApplianceVersion()
{
    if [ -f /etc/Novell-VA-release ]; then
		applianceVersion=$(cat /etc/Novell-VA-release | grep version  | cut -d= -f2 |sed -e 's/^[ \t]*//')	
	fi
}

###################################################
ndsOutput ()
{

	plugin_tag "Section #5" "eDirectory and Cert Information"
	
	if [ -L /var/opt/novell/iprint ]; then
		clusterVolPath=$(ls -al /var/opt/novell/ | grep /media/nss | cut -d'>' -f2 | cut -d/ -f1-4 |  sed -e 's/^[ \t]*//')
		plugin_tag "$EDIR_LABEL" "rights -f $clusterVolPath/etc/opt/novell/iprint show"
		rights -f $clusterVolPath/etc/opt/novell/iprint show

		plugin_tag "$EDIR_LABEL" "rights -f $clusterVolPath/var/opt/novell/iprint show"
		rights -f $clusterVolPath/var/opt/novell/iprint show

		plugin_tag "$EDIR_LABEL" "rights -f $clusterVolPath/var/opt/novell/log/iprint show"
		rights -f $clusterVolPath/var/opt/novell/log/iprint show
	fi

	plugin_tag "$EDIR_LABEL" "ndsstat -r"
	ndsstat -r; echo
	
	plugin_tag "$EDIR_LABEL" "ndsrepair -T"
	ndsrepair -T; echo
	
	plugin_tag "$EDIR_LABEL" "ndsrepair -E"
	ndsrepair -E; echo
	
	if [ -n "$EDIR_USERNAME" ]; then
		plugin_tag "$EDIR_LABEL" "ldapconfig get -p localhost -a $EDIR_USERNAME"
		ldapconfig get -p localhost -a $EDIR_USERNAME -w $EDIR_PASSWORD; echo

		plugin_tag "$EDIR_LABEL" "ldapconfig get -p $iprint_ssl_URL -a $EDIR_USERNAME"
		ldapconfig get -p $iprint_ssl_URL -a $EDIR_USERNAME -w $EDIR_PASSWORD; echo

		plugin_tag "$EDIR_LABEL" "ldapconfig get -p $nam_conf_server -a $EDIR_USERNAME"
		ldapconfig get -p $nam_conf_server -a $EDIR_USERNAME -w $EDIR_PASSWORD; echo
	else
		plugin_tag "$EDIR_LABEL" "Run iPrintInfo -h for additional LDAP information"
	fi
	
	#Identifies whether the uid of the user can be found
	UID_NAME=$(echo $EDIR_USERNAME | cut -d. -f1)	
	plugin_tag "$EDIR_LABEL" "ldapsearch -x uid=$UID_NAME dn | grep dn: | sed s'/dn: //'"
	echo '#  This command will display whether the uid for the admin account is searchable and has the correct rights'
	ldapsearch -x uid=$UID_NAME dn | grep dn: | sed s'/dn: //'
	echo
	
	#Shows you what public assigned rights have been assigned to the root of the tree.	
	treeName=$(grep AuthName  /etc/opt/novell/iprint/httpd/conf/iprint_ssl.conf | cut -d\" -f2 | sed -e 's/^[ \t]*//')
	plugin_tag "$EDIR_LABEL" "(From localhost) /opt/novell/eDirectory/bin/ldapsearch -h localhost -p 636 -D $EDIR_LDAP_FQN -W -e /etc/opt/novell/certs/SSCert.der -b t=$treeName -s base ACL | grep Public"
	
	echo 'Numberic Key for Assigned Rights:'
	echo '1#-Compare or Browse'
	echo '2#-Read'
	echo '3#-Compare and Read'
	echo
	/opt/novell/eDirectory/bin/ldapsearch -h localhost -p 636 -D $EDIR_LDAP_FQN -w $EDIR_PASSWORD -e /etc/opt/novell/certs/SSCert.der -b t=$treeName -s base ACL | grep Public
	echo
	
	UniqueNames "ldapsearch"
	
	#This only executes if  iprint is on a NSS volume.
	if [ -n "$EDIR_USERNAME" ] && [ -h /var/opt/novell/iprint ]; then	
		plugin_tag "$EDIR_LABEL" "(From localhost) /opt/novell/eDirectory/bin/ldapsearch -h localhost -p 636 -D $EDIR_LDAP_FQN -W -e /etc/opt/novell/certs/SSCert.der \"cn=UNIX Workstation - $tmpSrvName\""
		UNIX_Output=$(/opt/novell/eDirectory/bin/ldapsearch -h localhost -p 636 -D $EDIR_LDAP_FQN -w $EDIR_PASSWORD -e /etc/opt/novell/certs/SSCert.der "cn=UNIX Workstation - $tmpSrvName" | grep ^\# --invert-match | sed '/^$/d')
		echo "$UNIX_Output"; echo	
		
		#Find the members of the iprintgrp group		
		iprintgrp_context=($(echo "$UNIX_Output" | grep iprintgrp | cut -d" " -f2-))		
		#echo "iprintgrp_context: $iprintgrp_context"		
		addArrayIndex=0
		SAVEIFS=$IFS
		IFS=$(echo -en "\n\b")
		iprintgrpArrayLen=${#iprintgrp_context[@]}
		
		for (( i=0; i<${iprintgrpArrayLen}; i++ ));
		do
			plugin_tag "$EDIR_LABEL" "(From localhost) /opt/novell/eDirectory/bin/ldapsearch -h localhost -p 636 -D $EDIR_LDAP_FQN -W -e /etc/opt/novell/certs/SSCert.der -b "${iprintgrp_context[$i]}""			
			iprintgrp_Output_Array[${addArrayIndex}]=$(/opt/novell/eDirectory/bin/ldapsearch -h localhost -p 636 -D $EDIR_LDAP_FQN -w $EDIR_PASSWORD -e /etc/opt/novell/certs/SSCert.der -b "${iprintgrp_context[$i]}" | grep ^\# --invert-match | sed '/^$/d')							
		        echo "${iprintgrp_Output_Array[addArrayIndex]}"
		        echo
		        
		        #Display contents of the iPrint user
		        iprint_context=($(echo "${iprintgrp_Output_Array[addArrayIndex]}" | grep 'member: cn=iprint,' | cut -d" " -f2-))		        
		        iprintArrayLen=${#iprint_context[@]}		        
		        addArrayIndex2=0
		        
		        for (( j=0; j<${iprintArrayLen}; j++ ));
			do
				plugin_tag "$EDIR_LABEL" "(From localhost) /opt/novell/eDirectory/bin/ldapsearch -h localhost -p 636 -D $EDIR_LDAP_FQN -W -e /etc/opt/novell/certs/SSCert.der -b "${iprint_context[$j]}""
				iprint_Output_Array[${addArrayIndex2}]=$(/opt/novell/eDirectory/bin/ldapsearch -h localhost -p 636 -D $EDIR_LDAP_FQN -w $EDIR_PASSWORD -e /etc/opt/novell/certs/SSCert.der -b "${iprint_context[$j]}" | grep ^\# --invert-match | sed '/^$/d')
				echo "${iprint_Output_Array[addArrayIndex2]}"
				#echo "addArrayIndex2: $addArrayIndex2"
				((addArrayIndex2++)) #Allows the script to increment through the iprint user in that particular group
				echo			
			done		        
		        ((addArrayIndex++)) #Allows the script to increment through the iprintgrp	
			echo
		
		done
		IFS=$SAVEIFS				
		
	fi			
	
	pathsToList="/etc/opt/novell/certs/ /etc/ssl/servercerts/"
	if [ ! -z $applianceVersion ];then
		pathsToList="$pathsToList /vastorage/conf/certs"
	fi
	
	for pathVar in $pathsToList
	do
		plugin_tag "$EDIR_LABEL" "ls -al $pathVar"
		ls -al $pathVar; echo
	done

	if [ $oesVersion != "11" ]; then
		if certtool -i --inder --infile /etc/opt/novell/certs/SSCert.der &>/dev/null; then
			plugin_tag "$EDIR_LABEL" "certtool -i --inder --infile /etc/opt/novell/certs/SSCert.der"
			certtool -i --inder --infile /etc/opt/novell/certs/SSCert.der | sed "/Subject:/,/modulus:/!d"; echo
			
		else
			plugin_tag "$EDIR_LABEL" "certtool -i --inder --infile /etc/opt/novell/certs/SSCert.der"
			certtool -i --inder --infile /etc/opt/novell/certs/SSCert.der; echo
		fi
			
		CERTS="/etc/opt/novell/certs/SSCert.pem /etc/ssl/servercerts/servercert.pem"
		
		if [ ! -z $applianceVersion ]; then
			CERTS="$CERTS /vastorage/conf/certs/vaserver.crt"
		fi
		for certFile in $CERTS
		do
			if certtool -i --infile $certFile &>/dev/null; then
				plugin_tag "$EDIR_LABEL" "certtool -i --infile $certFile"
				certtool -i --infile $certFile | sed "/Subject:/,/modulus:/!d"; echo
			else
				plugin_tag "$EDIR_LABEL" "certtool -i --infile $certFile"
				"certtool -i --infile $certFile"; echo
			fi
		done
	fi



	#Checks the connection to the SSCert.pem file through openssl
	plugin_tag "$EDIR_LABEL" "echo -n | SSL_CERT=/no_dir openssl s_client -connect localhost:636 -CAfile /etc/opt/novell/certs/SSCert.pem -verify 255"
	echo -n | SSL_CERT=/no_dir openssl s_client -connect localhost:636 -CAfile /etc/opt/novell/certs/SSCert.pem -verify 255 | sed '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/d'; echo
}

###################################################
MiscCommands ()
{
	plugin_tag "Section #6" "Miscellaneous Commands"
	echo "EDIR_LDAP_FQN: $EDIR_LDAP_FQN"
	
	if [ $oesVersion != "11" ]; then
	plugin_command 'rpm -qa --last | grep "openwbem\|iprint\|apache"'	
	fi
	
	if [ -n "$EDIR_USERNAME" ]; then
		if [ $oesVersion == "11" ]; then				
			plugin_tag "$COMM_LABEL" "iprintman psm -l -u $EDIR_LDAP_FQN"
			export IPRINTMAN_PASSWORD=$EDIR_PASSWORD
			iprintman psm -l -u $EDIR_LDAP_FQN --accept-cert; echo
			unset IPRINTMAN_PASSWORD
		else
			UID_NAME=$(echo $EDIR_USERNAME | cut -d. -f1)	
			plugin_tag "$COMM_LABEL" "iprintman psm -l -u $UID_NAME"	
			export IPRINTMAN_PASSWORD=$EDIR_PASSWORD
			iprintman psm -l -u $UID_NAME --accept-cert; echo
			unset IPRINTMAN_PASSWORD
		fi
	else
		plugin_tag "$EDIR_LABEL" "Run iPrintInfo for additional iprintman information"
	fi
	
	
	plugin_command "ps -eaf | egrep 'iprint'"
	if [ $oesVersion != "11" ]; then
		plugin_command "ps -eaf | egrep 'owcimomd'"
	fi
	plugin_command "ps -eaf | egrep 'apache2'"
	if [ $oesVersion != "11" ]; then
		plugin_command "/etc/init.d/owcimomd status"
	fi
	plugin_command "chkconfig -l cups"
	plugin_command "chkconfig -l novell-ipsmd"
	plugin_command "/etc/init.d/cups status"
	plugin_command "/etc/init.d/novell-ipsmd status"
	plugin_command "/etc/init.d/apache2 status"
	
	if [ ! -z $applianceVersion ]; then
		plugin_command "/usr/sbin/rcnovell-jetty check"
		plugin_command "rcnovell-iprint-mobile status"
		plugin_command "rcavahi-daemon status"
		plugin_command "ps -aef | grep -i Jetty"
		plugin_command "ps -aef | grep -i MySql"
		plugin_command "ps -aef | grep libreoffice"
		plugin_command "ps -aef | grep avahi"
	fi		
	
	plugin_command "uname -a"
	plugin_command "uptime"
	pingDNSNames
	
	
	plugin_tag "$COMM_LABEL" "ifconfig | grep 'inet addr'"
	ifconfig | grep "inet addr" | sed "s/^[ \t]*//"; echo

	eName=`echo $EDIR_USERNAME | cut -d. -f1` 	
	if [ -n "$eName" ]; then
		if [ $eName == "admin" ]; then
			plugin_command "id $eName"
		else		
			plugin_command "id admin"
			plugin_command "id $eName"
		fi
	else
		plugin_command "id admin"
	fi
	plugin_command "id wwwrun"
	plugin_command "id iprint"
	plugin_command "netstat -atnp | egrep \"636|389\" | grep -i listen"
	plugin_command "netstat -atnp | grep httpd | grep -i listen"	
	UniqueNames "netcat"
	plugin_command "rcSuSEfirewall2 status"
	plugin_command "df -h"
	plugin_command "free -k"
	plugin_command "mount | grep nssvol"
	plugin_command "getent passwd | grep wwwrun"
	plugin_command "getent group | grep www"
	plugin_command "ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10 | grep -e iPrintInfo --invert-match"

	if [ -h /var/opt/novell/iprint ]; then
        if [ -n "$eName" ]; then
                if [ $eName == "admin" ]; then
			plugin_command "namuserlist -f $eName"
                else
                	plugin_command "namuserlist -f admin"
			plugin_command "namuserlist -f $eName"
                fi
        else
		 plugin_command "namuserlist -f admin"
        fi

	

        plugin_command "namuserlist -f iprint"
        plugin_command "namuserlist -f wwwrun"
	fi
	plugin_command "namuserlist -x $EDIR_SEARCH_BASE"
	plugin_command "namgrouplist -x $EDIR_SEARCH_BASE"
}
###################################################
isNumber()
{
#This identifies if the value is a digit or not.
removedDotsVar=$(echo "$1" |sed "s/\.//g")
  if expr $removedDotsVar + 1 &> /dev/null ; then
    return 0
  else
    return 1
  fi
}
###################################################
pingDNSNames ()
{
#This for loop will read in each dns name or ip address and put them in a list
for i in $iprint_ssl_URL $ipsmd_conf_dsserver1 $ipsmd_conf_psmhostaddress $nam_conf_server
do	
	list=$(printf "%s\n%s\n" $list $i)
done

uniqList=$(echo "$list" | sort | uniq)
#This for loop will identify if they are IP adresses (is Digit) or dns names
for i in $uniqList
do	
	fromFileNames=""
	isNumber "$i"
	returnCode=$?
	#echo "returncode: $returnCode"
	if [ $returnCode == "1" ]; then
		#this for loop identifies what file or value contains that adress that is being pinged.
		for j in ${iprint_ssl_URL}:iprint_ssl.conf ${ipsmd_conf_dsserver1}:DSServer1 $ipsmd_conf_psmhostaddress:PSMHostAddress $nam_conf_server:nam.conf
		do 
			dnsNameUrl=$(echo $j | cut -d: -f1)
			fromFile=$(echo $j | cut -d: -f2)
			if [ "$dnsNameUrl" == "$i" ]; then				
				if [ -z $fromFileNames ]; then
					fromFileNames=$fromFile
				else
					fromFileNames="${fromFileNames}, $fromFile"
					#echo "fromFileNames:$fromFileNames"
				fi
			fi
		done
		plugin_command "ping -c2 $i #From $fromFileNames"
	fi
done
}
###################################################
UniqueNames ()
{

#This for loop will read in each dns name or ip address and put them in a list
for i in $iprint_ssl_URL $ipsmd_conf_dsserver1 $ipsmd_conf_psmhostaddress $nam_conf_server
do	
	list=$(printf "%s\n%s\n" $list $i)
done

#this will create a unique list of values.
uniqList=$(echo "$list" | sort | uniq)

for i in $uniqList
do	
	fromFileNames=""
	#this for loop identifies what file or value contains the address that is being used for netcat
	for j in ${iprint_ssl_URL}:iprint_ssl.conf ${ipsmd_conf_dsserver1}:DSServer1 $ipsmd_conf_psmhostaddress:PSMHostAddress $nam_conf_server:nam.conf
	do 
		dnsNameUrl=$(echo $j | cut -d: -f1)
		fromFile=$(echo $j | cut -d: -f2)
		if [ "$dnsNameUrl" == "$i" ]; then				
			if [ -z "$fromFileNames" ]; then
				fromFileNames=$fromFile
			else
				fromFileNames="${fromFileNames}, $fromFile"
				#echo "fromFileNames:$fromFileNames"
			fi
		fi
	done
	if [ $1 == "netcat" ];then
		plugin_command "netcat -zv $i 636 #From $fromFileNames"
		plugin_command "netcat -zv $i 5989 #From $fromFileNames"

	elif [ $1 == "ldapsearch" ]; then
		if [ -n "$EDIR_LDAP_FQN" ]; then
			tmpSrvName=`ndsstat -h $dnsNameUrl 2>&1 | grep "Server Name" | cut -d. -f2 | cut -d= -f2` >/dev/null
			if [ -z "$tmpSrvName" ]; then
				plugin_message "# ndsstat failed using command: ndsstat -h $dnsNameUrl"
			else
				plugin_message "#==[ $EDIR_LABEL ]======================================#"
				plugin_message "# (From $fromFileNames) /opt/novell/eDirectory/bin/ldapsearch -h $i -p 636 -D $EDIR_LDAP_FQN -W -e /etc/opt/novell/certs/SSCert.der \"cn= SSL CertificateDNS - $tmpSrvName\""
				/opt/novell/eDirectory/bin/ldapsearch -h $i -p 636 -D $EDIR_LDAP_FQN -w $EDIR_PASSWORD -e /etc/opt/novell/certs/SSCert.der "cn= SSL CertificateDNS - $tmpSrvName" | sed '/nDSPKICertificateChain:/,/objectClass:/d'		
				plugin_message
			fi
		
		else
			plugin_message "#==[ Warning ]======================================#"
			plugin_message "# Run iPrintInfo -b for secure LDAP connection test"
			plugin_message
		fi
	fi
done



}
###################################################
displayXML ()
{

	if [ -e /opt/novell/iprint/bin/psmimport.xml ]; then
		plugin_tag "$XML_LABEL" "/opt/novell/iprint/bin/psmimport.xml"
		cat /opt/novell/iprint/bin/psmimport.xml; echo
	else
		plugin_tag "$XML_LABEL" "/opt/novell/iprint/bin/psmimport.xml - File Not Found"
	
	fi
	
	plugin_tag "$XML_LABEL" "/var/opt/novell/iprint/$managerName.psm/padbtxt.xml"
	cat "/var/opt/novell/iprint/$managerName.psm/padbtxt.xml"; echo
	
	if [ ! -z $applianceVersion ]; then
		plugin_tag "$XML_LABEL" "/var/opt/novell/iprintmobile/iprintmobiledb.xml"
		cat "/var/opt/novell/iprintmobile/iprintmobiledb.xml"; echo
	fi	
}



###################################################
LogOutput ()
{
	plugin_tag "Section #7" "Log Output Files"
	#echo $managerName
	#managerName2=`echo $managerName | sed "s/[[:space:]]/\\ /g"`
	#echo $managerName2	
	
	
	
	logFiles="/var/opt/novell/log/iprint/idsd.log /var/opt/novell/log/iprint/ipsmd.log /var/opt/novell/log/iprint/ipsmprov.log /var/log/messages"
	
	if [ ! -z $applianceVersion ];then
		logFiles="$logFiles /var/opt/novell/log/iprintmobile/iprintmobile0.log  /var/opt/novell/log/iprintmobile/iprintmobile_config.log /var/opt/novell/log/iprintmobile_local/config_appliance.log /var/opt/novell/log/iprintmobile/config_appliance.log /var/opt/novell/log/iprint_relocate.err /var/opt/novell/log/iprintmobile/backup.log /var/opt/novell/log/iprintmobile_local/restore.log /var/opt/novell/log/iprintmobile/restore.log /opt/novell/filr/apache-tomcat/webapps/ssf/WEB-INF/logs/ssf.log /var/opt/novell/jetty8/logs/jetty.stderrout.out"
	fi
	plog_files $LOG_LINES $logFiles
	
	plog_files $LOG_LINES "/var/log/apache2/error_log"
	plog_files $LOG_LINES2 "/var/log/apache2/access_log /var/lib/novell-lum/nam.log"
	plog_files $LOG_LINES2 "/var/opt/novell/log/iprint/iprintgw.log"
	
	plugin_tag "$LOG_LABEL" "/var/opt/novell/iprint/$managerName.psm/ndpsmmon.log - Last $LOG_LINES2 Lines"	
	tail -$LOG_LINES "/var/opt/novell/iprint/$managerName.psm/ndpsmmon.log"; echo
	if [ $oesVersion == "11" ]; then
		
		if [ -e "/var/opt/novell/log/iprintmgmt/iprintman0.log" ]; then
			plugin_tag "$LOG_LABEL" "/var/opt/novell/log/iprintmgmt/iprintman[X].log - Last $LOG_LINES3 Lines"	
			tail -n $LOG_LINES3 /var/opt/novell/log/iprintmgmt/iprintman*.log; echo
		
		else
			plugin_tag "$LOG_LABEL" "/var/opt/novell/log/iprintmgmt/iprintman0.log - File Not Found"	
		fi
	fi
	
	if [ -e "/var/opt/novell/log/iprint_nss_relocate.log" ]; then
		plog_files $LOG_LINES "/var/opt/novell/log/iprint_nss_relocate.log"	

	else 	
		plugin_tag "$LOG_LABEL" "/var/opt/novell/log/iprint_nss_relocate.log - File Not Found"
	fi
	
}

checkPersistentCredentials ()
{
	if [ "$AUTH_PERSISTENT" != "true" ]; then
cat <<PGCONF_EOF > $PGCONF
EDIR_USERNAME=""
EDIR_PASSWORD=""
EDIR_SEARCH_BASE=""
EDIR_LDAP_FQN=""
AUTH_PERSISTENT="false"
PGCONF_EOF
	fi
}

QueryRPMs ()
{
	#Enters all of the installed iprint rpms into an array for use in another function.
	rpmArray=`rpm -qa | grep iprint | sort -d`	
	
	if [ ! -z $applianceVersion ]; then
		#Add Libre office rpms
		rpmArray+=`rpm -qa | grep libre | sort -d`
	fi
}
###################################################
setVariables ()
{

	# This gives us the ldaps URL servers DNS or IP address from the iprint_ssl.conf
	iprint_ssl_URL=`grep -i AuthLDAPDNURL /etc/opt/novell/iprint/httpd/conf/iprint_ssl.conf | cut -d/ -f3 | cut -d: -f1`
	
	#This gives us the preferred server's DNS or IP address from the nam.conf
	nam_conf_server=`grep -i preferred-server /etc/nam.conf | cut -d= -f2`
	
	#This gives us the Dsserver1 DNS or IP address from the ipsmd.conf
	ipsmd_conf_dsserver1=` grep -i DSServer1 /etc/opt/novell/iprint/conf/ipsmd.conf | tr -s ' ' | cut -d" " -f2`

	#This gives us the Dsserver1 DNS or IP address from the ipsmd.conf
	ipsmd_conf_psmhostaddress=` grep -i PSMHostAddress /etc/opt/novell/iprint/conf/ipsmd.conf | tr -s ' ' | cut -d" " -f2`


	
}
###################################################
execCalls ()
{
	#Executes each of the functions
	checkOESVersion
	checkApplianceVersion
	checkPersistentCredentials
	QueryRPMs
	PackageValidation
	ListRights
	ListRightsStatic
	setVariables
	FileOutput
	ndsOutput
	MiscCommands
	#getPSM
	displayXML
	LogOutput
}
###################################################

	
execCalls


